<?php
// +----------------------------------------------------------------------
// | 车钉钉 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.twothink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: YagamiZN
// +----------------------------------------------------------------------
namespace app\admin\model;
use think\Model;

/**
 * 产品模型
 */

class Product extends Model{
    
    protected $autoWriteTimestamp = true;   
    protected $table = 'cdd_car';
    //protected $error;//错误信息
    
    /**
     * 添加产品 
     * @return boolean 更新状态
     */
    public function insert($data){
        if(!$data){ //数据对象创建错误
            return false;
        }
        $validate = validate('Product');
        /* 添加或更新数据 */
        if(empty($data['id'])){
            if(!$validate->check($data)){
                //exit(json_encode(['code'=>$validate->getError()]));
                return $this->error=$validate->getError();
            }
            $res = $this->allowField(true)->save($data);
            $res = $this->id;
        }else{
            if(!$validate->check($data)){
                return $this->error=$validate->getError();
            }
            $res = $this->update($data);
        }
        return $res;
    }
}
